

//
//  ZTSiginViewController.m
//  ZTTaxSecond
//
//  Created by Zhengtong on 15/11/17.
//  Copyright © 2015年 Zhengtong. All rights reserved.
//

#import "ZTSiginViewController.h"

#import "ZTNextSiginController.h"

#import "NSObject+ToolObject.h"

@interface ZTSiginViewController ()
- (IBAction)nextBtnClick:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UIImageView *topImageView;

@property (weak, nonatomic) IBOutlet UITextField *taxerTextField;
@property (weak, nonatomic) IBOutlet UITextField *pswTextField;
@property (weak, nonatomic) IBOutlet UITextField *queRePswTextField;


@end

@implementation ZTSiginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    
    self.navigationController.navigationBar.hidden = NO;
    self.title = @"我要注册";
    [self setUpNavgationBar];
    

    
    [self removeNotification];
    [self addKeyBoardNotification];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
    [self.view addGestureRecognizer:tap];
    
}
- (void)viewWillLayoutSubviews
{
    self.topImageView.frame = CGRectMake((DEVICE_WIDTH-258)/2, 20, 258, 41);
    [self.topImageView setNeedsDisplay];
}
- (void)tapGesture:(UITapGestureRecognizer *)tap
{
    [self.taxerTextField resignFirstResponder];
    [self.pswTextField resignFirstResponder];
    [self.queRePswTextField resignFirstResponder];
}
#pragma mark - 设置导航条
- (void)setUpNavgationBar
{
    //导航条背景图片
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"上栏"] forBarMetrics:UIBarMetricsDefault];
    //导航标题颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 10, 16);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"返回按钮"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //rightItem
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 60, 20);
    [rightBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)leftBtnClick
{
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)rightBtnClick:(UIButton *)btn
{
    [self nextLoadData];
}
- (IBAction)nextBtnClick:(UIButton *)sender {
    [self nextLoadData];
}

- (void)nextLoadData
{
    if (![self judgmentIsEmpty:self.taxerTextField.text]) {
        [self showHUD:@"纳税人代码不能为空"];
    }else if (![self judgmentIsEmpty:self.pswTextField.text]){
        [self showHUD:@"密码不能为空"];
    }else if (![self judgmentIsEmpty:self.queRePswTextField.text]){
        [self showHUD:@"确认密码不能为空"];
    }else if (![self.pswTextField.text isEqualToString:self.queRePswTextField.text]){
        [self showHUD:@"密码不一致"];
    }else{
        [RequestTool requestSiginUserId:self.taxerTextField.text WithBlock:^(id result, NSString *error) {
            if (error == nil) {
                ZTNextSiginController *next = [[ZTNextSiginController alloc] init];
                next.useId = self.taxerTextField.text;
                next.psw   = self.pswTextField.text;
                [self.navigationController pushViewController:next animated:NO];
            }else{
                [self showHUD:error];
            }
        }];
    }
    
  
}

@end
